package com.hanson.controller;

import com.hanson.common.bean.ResultMessage;
import com.hanson.service.GoodsCollectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/web/goodsCollect")
public class WebGoodsCollectController {
    @Autowired
    private GoodsCollectService goodsCollectService;

    @RequestMapping(value = "/add/{goodsId}", method = RequestMethod.POST)
    public ResultMessage add(@PathVariable String goodsId, @CookieValue("openId") String openId) throws Exception {
        goodsCollectService.add(goodsId, openId);
        ResultMessage resultMessage = new ResultMessage();
        resultMessage.setMsg("添加收藏成功！");
        return resultMessage;
    }

    @RequestMapping(value = "/delete/{goodsId}", method = RequestMethod.POST)
    public ResultMessage delete(@PathVariable String goodsId, @CookieValue("openId") String openId) throws Exception {
        goodsCollectService.delete(openId, Integer.parseInt(goodsId));
        ResultMessage resultMessage = new ResultMessage();
        resultMessage.setMsg("删除收藏成功！");
        return resultMessage;
    }
}
